//
//  BK_my_ContactPeople.m
//  bestkeep
//
//  Created by bj on 2016/11/10.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BK_my_ContactPeople.h"

@implementation BK_my_ContactPeople


-(void)parsePerson:(ABRecordRef)person{
    [self read:person];
}

-(void)read:(ABRecordRef)person{
    
    NSString *prefix = (__bridge NSString*)ABRecordCopyValue(person, kABPersonPrefixProperty);
    if (prefix != nil) {
        self.name = prefix;
    }else{
        self.name = @"";
    }
    NSString *lastname = (__bridge NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty);
    if (lastname != nil) {
        self.name = [self.name stringByAppendingString:lastname];
    }
    NSString *middlename = (__bridge NSString*)ABRecordCopyValue(person, kABPersonMiddleNameProperty);
    if (middlename != nil) {
        self.name = [self.name stringByAppendingString:middlename];
    }
    NSString *personName = (__bridge NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
    if(personName != nil)
        self.name = [self.name stringByAppendingString:personName];
    
    
    NSString *suffix = (__bridge NSString*)ABRecordCopyValue(person, kABPersonSuffixProperty);
    if (suffix != nil) {
        self.name = [self.name stringByAppendingString:suffix];
    }
    
    ABMultiValueRef phone = ABRecordCopyValue(person, kABPersonPhoneProperty);
    for (int k = 0; k<ABMultiValueGetCount(phone); k++)
    {
        NSString * personPhone = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phone, k);
        self.telephone = personPhone;
    }

    NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@"@／：；（）¥「」＂、[]{}#%-*+=_\\|~＜＞$€^•'@#$%^&*()_+'\"- "];
    NSString *telephone =[[self.telephone componentsSeparatedByCharactersInSet:set]componentsJoinedByString:@""];
    self.telephone = telephone;
}

@end
